package com.yunpuvip.sachet.modular.util;

import java.math.BigDecimal;


/**
 * BigDecimal计算封装
 *
 * @author hyf
 * @date 2018/8/15
 **/
public class BigDecimalUtil {

    private BigDecimalUtil() {

    }

    @Deprecated
    public static BigDecimal add(double v1, double v2) {
        BigDecimal b1 = new BigDecimal(Double.toString(v1));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        return b1.add(b2);
    }

    @Deprecated
    public static BigDecimal subtract(double v1, double v2) {
        BigDecimal b1 = new BigDecimal(Double.toString(v1));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        return b1.subtract(b2);
    }

    @Deprecated
    public static BigDecimal multiply(double v1, double v2) {
        BigDecimal b1 = new BigDecimal(Double.toString(v1));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        return b1.multiply(b2).setScale(2, BigDecimal.ROUND_UP);
    }

    @Deprecated
    public static BigDecimal divide(double v1, double v2) {
        BigDecimal b1 = new BigDecimal(Double.toString(v1));
        BigDecimal b2 = new BigDecimal(Double.toString(v2));
        return b1.divide(b2, 2, BigDecimal.ROUND_UP);
    }

    public static BigDecimal multiply(String v1, String v2) {
        BigDecimal b1 = new BigDecimal(v1);
        BigDecimal b2 = new BigDecimal(v2);
        return b1.multiply(b2).setScale(2, BigDecimal.ROUND_UP);
    }

    public static BigDecimal multiply(BigDecimal v1, BigDecimal v2) {
        return v1.multiply(v2).setScale(2, BigDecimal.ROUND_UP);
    }

    public static BigDecimal multiply(BigDecimal v1, Integer v2) {
        BigDecimal b2 = new BigDecimal(v2 + "");
        return v1.multiply(b2).setScale(2, BigDecimal.ROUND_UP);
    }

}
